/*
 * FileName：AccountServiceImpl.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.wx.wxcms.service.impl;

import com.smart.wx.wxcms.dao.*;
import com.smart.wx.wxcms.entity.*;
import com.smart.wx.wxcms.service.AccountService;
import org.springframework.data.annotation.Transient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author hermit
 * @version 2.0
 * @date 2018-04-17 10:54:58
 */
@Service("accountService")
public class AccountServiceImpl implements AccountService {

    @Resource
    private AccountMapper accountMapper;
    @Resource
    private AccountFansMapper accountFansMapper;
    @Resource
    private AccountMenuMapper accountMenuMapper;
    @Resource
    private MsgArticleMapper msgArticleMapper;
    @Resource
    private MsgNewsMapper msgNewsMapper;
    @Resource
    private ImgResourceMapper imgResourceMapper;
    @Resource
    private MediaFilesMapper mediaFilesMapper;
    @Resource
    private MsgBaseMapper msgBaseMapper;
    @Resource
    private MsgRecordMapper msgRecordDao;
    @Resource
    private MsgTextMapper msgTextMapper;
    @Resource
    private PaperInfoMapper paperInfoDao;
    @Resource
    private PaperOptionMapper pageOptionDao;
    @Resource
    private PaperQuestionMapper paperQuestionDao;
    @Resource
    private PaperRecordMapper paperRecordDao;
    @Resource
    private ReplyAutoMapper replyAutoDao;
    @Resource
    private ReplyKeyMapper replyKeyDao;
    @Resource
    private ReplyKeywordMapper replyKeywordDao;
    @Resource
    private  TplMsgTextMapper tplMsgTextMapper;
    @Resource
    private UserTagMapper userTagMapper;
    @Resource
    private VoteApplyMapper voteApplyDao;
    @Resource
    private VoteMapper voteMapper;
    @Resource
    private VoteRecordMapper voteRecordDao;
    @Resource
    private WebsiteBannerMapper websiteBannerDao;
    @Resource
    private WebsiteBrandIntroductionMapper websiteBrandIntroductionDao;
    @Resource
    private WebsiteContactUsMapper websiteContactUsDao;
    @Resource
    private WebsiteCoreBusinessMapper websiteCoreBusinessDao;
    @Resource
    private WebsiteMessageBoardMapper websiteMessageBoardDao;
    @Resource
    private WebsiteNewsCenterMapper websiteNewsCenterDao;
    @Resource
    private WebsiteServiceIntroductionMapper websiteServiceIntroductionDao;


    public Account getById(Long id) {
        return accountMapper.getById(id);
    }

    public Account getByAccount(String account) {
        return accountMapper.getByAccount(account);
    }

    public List<Account> listForPage(Account account) {
        return accountMapper.listForPage(account);
    }

    public void add(Account account) {
        accountMapper.add(account);
    }

    public void update(Account account) {
        accountMapper.update(account);
    }

    @Transient
    public void delete(String accountStr) throws Exception{
        //刪除粉丝
        AccountFans accountFans=new AccountFans();
        accountFans.setAccount(accountStr);
        accountFansMapper.delete(accountFans);
        //刪除菜单
        AccountMenu accountMenu=new AccountMenu();
        accountMenu.setAccount(accountStr);
        accountMenuMapper.delete(accountMenu);
        //删除图文
        MsgArticle msgArticle=new MsgArticle();
        msgArticle.setAccount(accountStr);
        msgArticleMapper.delete(msgArticle);
        MsgNews msgNews=new MsgNews();
        msgNews.setAccount(accountStr);
        msgNewsMapper.delete(msgNews);
        //删除图片
        ImgResource imgResource=new ImgResource();
        imgResource.setAccount(accountStr);
        imgResourceMapper.delete(imgResource);
        //删除素材
        MediaFiles mediaFiles=new MediaFiles();
        mediaFiles.setAccount(accountStr);
        mediaFilesMapper.delete(mediaFiles);
        //删除基础表
        MsgBase msgBase=new MsgBase();
        msgBase.setAccount(accountStr);
        msgBaseMapper.delete(msgBase);
        //删除群发记录
        msgRecordDao.deleteByAccount(accountStr);
        //删除文本
        MsgText msgText=new MsgText();
        msgText.setAccount(accountStr);
        msgTextMapper.delete(msgText);
//        //删除问卷
//        paperInfoDao.deleteByAccount(accountStr);
//        pageOptionDao.deleteByAccount(accountStr);
//        paperQuestionDao.deleteByAccount(accountStr);
//        paperRecordDao.deleteByAccount(accountStr);
        //删除回复相关
        ReplyAuto replyAuto=new ReplyAuto();
        replyAuto.setAccount(accountStr);
        replyAutoDao.delete(replyAuto);
        replyKeyDao.deleteByAccount(accountStr);
        replyKeywordDao.deleteByAccount(accountStr);
        //删除模板
        TplMsgText tplMsgText=new TplMsgText();
        tplMsgText.setAccount(accountStr);
        tplMsgTextMapper.delete(tplMsgText);
        //删除标签
        userTagMapper.deleteTTF(TagToFan.builder().account(accountStr).build());
        //删除投票
//        voteApplyDao.deleteByAccount(accountStr);
//        voteMapper.deleteByAccount(accountStr);
//        voteRecordDao.deleteByAccount(accountStr);
        //删除官网
        websiteBannerDao.deleteByAccount(accountStr);
        websiteBrandIntroductionDao.deleteByAccount(accountStr);
        websiteContactUsDao.deleteByAccount(accountStr);
        websiteCoreBusinessDao.deleteByAccount(accountStr);
        websiteMessageBoardDao.deleteByAccount(accountStr);
        websiteNewsCenterDao.deleteByAccount(accountStr);
        websiteServiceIntroductionDao.deleteByAccount(accountStr);
        //删除公众号
        Account account=new Account();
        account.setAccount(accountStr);
        accountMapper.delete(account);
    }

    public Account getSingleAccount(String userId) {
        return accountMapper.getSingleAccount(userId);
    }
    
}
